//
//  MANLeftViewController.m
//  Three
//
//  Created by 夜猫子 on 2017/3/22.
//  Copyright © 2017年 夜猫子. All rights reserved.
//

#import "MANLeftViewController.h"
#import "MANSliderViewController.h"
#import "MANMainViewController.h"
#import "CZAdditions.h"
#import "MANLeftTableViewCell.h"
#import "MANSrttingViewController.h"
#import "MANDoctorViewController.h"
#import "MANDoctApplyViewController.h"
#import "MANCaseManageViewController.h"

#define MANColor [UIColor cz_colorWithHex:0x20c6c6]

@interface MANLeftViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak) UITableView *tableView;

@property (nonatomic, strong) NSArray *arr;

@end

static NSString *MANCell = @"MANCell";

@implementation MANLeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
}


- (void)setupUI {
    
    UIView *topView = [[UIView alloc]init];
    [self.view addSubview:topView];
    topView.backgroundColor = [UIColor whiteColor];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.mas_equalTo(150);
    }];
    
    UITableView *tableView = [[UITableView alloc]init];
    [self.view addSubview:tableView];
    _tableView = tableView;
    tableView.backgroundColor = MANColor;
    tableView.separatorStyle = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom);
        make.left.bottom.right.equalTo(self.view);
    }];
    
    [tableView registerClass:[MANLeftTableViewCell class] forCellReuseIdentifier:MANCell];
    
    _arr = @[@{@"name":@"名医申请",@"picName":@"名医申请"},@{@"name":@"病历管理",@"picName":@"病历管理"},@{@"name":@"关注医生",@"picName":@"关注医生"},@{@"name":@"设置与帮助",@"picName":@"设置与帮助"}];
    
}

  
    

#pragma mark - UITableViewDataSourse
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _arr.count;
}
    
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MANLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MANCell forIndexPath:indexPath];
    
    cell.textLabel.text = _arr[indexPath.row][@"name"];
    cell.imageView.image = [UIImage imageNamed:_arr[indexPath.row][@"picName"]];
    
    return cell;
}

    

/**
 UITableViewDelegate
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //要让右侧控制器进行push
    MANSliderViewController *sliderVC = (MANSliderViewController *)self.parentViewController; //获取自己父控制器
    
    MANMainViewController *rightVC = (MANMainViewController *)sliderVC.rightVC;
    
    //要让右侧控制器进行push
    UINavigationController *nav = rightVC.selectedViewController; //代表获取选中的那个控制器
    
    if (indexPath.row == 0) {
        
        MANDoctApplyViewController *vc = [[MANDoctApplyViewController alloc] init];
        vc.view.backgroundColor = [UIColor whiteColor];
        [nav pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 1){
        MANCaseManageViewController *vc = [[MANCaseManageViewController alloc] init];
        vc.view.backgroundColor = [UIColor whiteColor];
        [nav pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 2){
        
        MANDoctorViewController *vc = [[MANDoctorViewController alloc] init];
        vc.view.backgroundColor = [UIColor whiteColor];
        [nav pushViewController:vc animated:YES];
        
    }else{
        
        MANSrttingViewController *vc = [[MANSrttingViewController alloc] init];
        vc.view.backgroundColor = [UIColor whiteColor];
        [nav pushViewController:vc animated:YES];
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //要让左侧控制器收回
    [sliderVC closeLeftVC];
}


@end
